<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Diffing算法</title>
</head>
<body>

    <div id="test"></div>



    <!-- 引入React核心库 -->
    <script src="../JS/new/react.development.js"></script>
    <!-- 引入ReactDOM，用于支持react操作DOM -->
    <script src="../JS/new/react-dom.development.js"></script>
    <!-- 引入babel 用于将书写的JSX语法 编译成JS语法 -->
    <script src="../JS/new/babel.min.js"></script>

    
    <script type="text/babel">
        class Time extends React.Component{
            state = {
                date:new Date()
            }
            componentDidMount(){
                setInterval(()=>{
                    this.setState({
                        date:new Date()
                    })
                },1000)
            }
            render(){
                console.log('更新了');
                return(
                    <div>
                        <h1>hello</h1>
                        <input type="text" />
                        <span>
                            现在是:{this.state.date.toTimeString()}
                            <input type="text" />
                        </span>
                    </div>
                )
            }
        }
        /* 
            总结陈词
                Diffing算法 计算的最小颗粒 是 标签
                所以 外层的h1`input 和 最里层的 input 都不会变 变得 只有 `现在是:{this.state.date.toTimeString()}`
                重新渲染的只有 `现在是:{this.state.date.toTimeString()}`
        */

        class Demo extends React.Component{
            constructor(props){
                super(props)
                this.state = {
                    isHot:true
                }
                this.changeWeather = this.change.bind(this)
            }
            change(){
                const {isHot} = this.state
                this.setState({
                    isHot:!isHot
                })
            }
            render(){
                const {isHot} = this.state
                return(
                    <div>
                        <h2>今天天气{isHot?'很炎热':'很凉爽'}</h2>    
                        <button onClick={this.changeWeather}>更改天气</button>
                    </div>
                )
            }
        }
        ReactDOM.render(<Time/>,document.getElementById('test'))
        // ReactDOM.render(<Demo/>,document.getElementById('test'))
        // ReactDOM.render(<Time/>),document.getElementById('test')
    </script>
</body>
</html>